package com.bianguo.android.apushdemo.model;

import com.bianguo.android.apushdemo.retrofit.ApiService;
import com.bianguo.android.apushdemo.utils.MyLog;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;
import okio.Buffer;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/4/21.
 */

public class BaseModel {

    public static final String getListGrid= "http://116.62.162.52:6060/fwzx/rest/ListGridService/getListGrid";
    public static final String post1 = "http://116.62.162.52:6060/fwzx/rest/CommonService/post1";

    public static final String BASE_URL = "https://api.douban.com/v2/movie/";
//    public static final String BASE_URL = "http://116.62.162.52:6060/fwzx/rest/";
    public static final String LOCATION_URL = "http://api.map.baidu.com/";
    private static final int DEFAULT_TIMEOUT = 20;
    protected ApiService apiService;

    public BaseModel(){
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(String message) {
                //打印retrofit日志
                MyLog.mLog("retrofitBack = "+message);
            }
        });
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
                .connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS)
//                .addInterceptor(loggingInterceptor)
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .client(client)
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();
        apiService = retrofit.create(ApiService.class);
    }
}
